package com.lehuowujie.lehuomarket.fragment;

import android.view.View;
import android.widget.ExpandableListView;

import com.lehuowujie.lehuomarket.R;
import com.lehuowujie.lehuomarket.base.BaseFragment;
import com.lehuowujie.lehuomarket.shop.ChildEntity;
import com.lehuowujie.lehuomarket.shop.ParentEntity;
import com.lehuowujie.lehuomarket.shop.ShopAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * 购物车
 * Created by 王瑞铭 on 2017/1/13.
 */
public class ShopFragment extends BaseFragment {

    public static final String TAG = ShopFragment.class.getName();

    public static ShopFragment mFragment;

    public static ShopFragment getInstance() {
        if (mFragment == null) {
            synchronized (ShopFragment.class) {
                if (mFragment == null)
                    mFragment = new ShopFragment();
            }
        }
        return mFragment;
    }

    private ExpandableListView mListView;

    private ShopAdapter adapter;

    private List<ParentEntity> mParentList = new ArrayList<>();

    @Override
    public int createView() {
        return R.layout.fragment_shop;
    }

    @Override
    public void initView() {
        initToolBar();
        setTitle(R.string.fragment_shop);
        mListView = (ExpandableListView) mContentView.findViewById(R.id.expandableListView);
        mListView.setGroupIndicator(null);
    }

    @Override
    public void initEvent() {
        initData();
        adapter = new ShopAdapter(getActivity(), mParentList);
        mListView.setAdapter(adapter);
        for (int i = 0; i < mParentList.size(); i++) {
            mListView.expandGroup(i);
        }
        mListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
            @Override
            public boolean onGroupClick(ExpandableListView expandableListView, View view, int i, long l) {
                return true;
            }
        });
    }

    private void initData() {
        List<ChildEntity> list1_1 = new ArrayList<>();
        ChildEntity e1_1 = new ChildEntity();
        e1_1.setShopName("");
        e1_1.setId("e1_1");
        list1_1.add(e1_1);
        ParentEntity p1_1 = new ParentEntity();
        p1_1.setParentName("");
        p1_1.setParentId("p1_1");
        p1_1.setShopList(list1_1);

        List<ChildEntity> list2_1 = new ArrayList<>();
        ChildEntity e2_1 = new ChildEntity();
        e2_1.setShopName("");
        e2_1.setId("e2_1");
        list2_1.add(e2_1);
        ChildEntity e2_2 = new ChildEntity();
        e2_2.setShopName("");
        e2_2.setId("e2_2");
        list2_1.add(e2_2);
        ParentEntity p2_1 = new ParentEntity();
        p2_1.setParentName("");
        p2_1.setParentId("p2_1");
        p2_1.setShopList(list2_1);

        List<ChildEntity> list3_1 = new ArrayList<>();
        ChildEntity e3_1 = new ChildEntity();
        e3_1.setShopName("");
        e3_1.setId("e3_1");
        list3_1.add(e3_1);
        ChildEntity e3_2 = new ChildEntity();
        e3_2.setShopName("");
        e3_2.setId("e3_2");
        list3_1.add(e3_2);
        ChildEntity e3_3 = new ChildEntity();
        e3_3.setShopName("");
        e3_3.setId("e3_3");
        list3_1.add(e3_3);
        ParentEntity p3_1 = new ParentEntity();
        p3_1.setParentName("");
        p3_1.setParentId("p3_1");
        p3_1.setShopList(list3_1);

        mParentList.add(p1_1);
        mParentList.add(p2_1);
        mParentList.add(p3_1);

    }
}
